package com.cooldatasoft.web.cms.user;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import com.cooldatasoft.app.WOCApplication;
import com.cooldatasoft.base.BaseListPage;
import com.cooldatasoft.web.cms.common.UserEditPanel;
import com.cooldatasoft.web.cms.person.dataProvider.UserListPageDataProvider;

public class UserListPage extends BaseListPage{

	private MarkupContainer listDiv;
	private FeedbackPanel feedbackPanel;
	
	public UserListPage(){
		
		
		
		MarkupContainer container= new WebMarkupContainer("container");		
		MarkupContainer header = new WebMarkupContainer("header");
		ExternalLink companyWebsiteLink = 
			new ExternalLink("companyWebsiteLink","http://www.cooldatasoft.com","Company Name");
		companyWebsiteLink.add(new AttributeModifier("target",true,new Model("_blank")));
		header.add(companyWebsiteLink);
		container.add(header);
		
	
		listDiv = new WebMarkupContainer("listDiv");
		feedbackPanel = new FeedbackPanel("feedbackPanel");
		listDiv.add(feedbackPanel);
		
		List<AbstractColumn> columns = new ArrayList<AbstractColumn>();
		
		columns.add(new PropertyColumn(new Model("Id"),"id","id"));
		columns.add(new PropertyColumn(new Model("Username"),"username","username"));
		columns.add(new PropertyColumn(new Model("Password"),"password"));
		
		columns.add(new AbstractColumn (new Model("Actions")){
			public void populateItem(Item cellItem, String componentId, IModel model){
				Component component = new UserEditPanel(componentId,model,feedbackPanel);
			    cellItem.add(component);
			}
		});
		
		listDiv.add(new AjaxFallbackDefaultDataTable("table", columns, new UserListPageDataProvider(), 
				WOCApplication.NUMBER_OF_RECORD_PER_PAGE));
			
		UserListPageForm entityListForm = new UserListPageForm("listForm");
		listDiv.add(entityListForm);
			
		container.add(listDiv);
		
		add(container);
	}	
	class UserListPageForm extends Form{

		public UserListPageForm(String id) {
			super(id);
            Button addButton=new Button("addButton"){
				public void onSubmit() {
                	setResponsePage(new UserViewPage(null));
                }
            };
            add(addButton);
		}
	}

}
